package com.jiawa.wiki.controller;

import com.jiawa.wiki.req.EbookQueryReq;
import com.jiawa.wiki.req.EbookSaveReq;
import com.jiawa.wiki.resp.CommomResp;
import com.jiawa.wiki.resp.EbookQueryResp;
import com.jiawa.wiki.resp.PageResp;
import com.jiawa.wiki.service.EbookService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/ebook")
public class EbookController {





    @Resource
    private EbookService ebookService;

    @GetMapping("/list")
    public CommomResp list(@Valid EbookQueryReq req){
        PageResp<EbookQueryResp> list = ebookService.getlist(req);

        CommomResp<PageResp<EbookQueryResp>> resp = new CommomResp<>();
        resp.setContent(list);
        return resp;

    }

    @PostMapping ("/save")
    public CommomResp save(@RequestBody EbookSaveReq req){

        CommomResp resp = new CommomResp<>();
        ebookService.save(req);
        return resp;

    }

    @DeleteMapping("/delete/{id}")
    public CommomResp delete(@PathVariable long id){
        CommomResp resp = new CommomResp<>();

        ebookService.delete(id);

        return resp;

    }


}

